<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <style>

    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-header-g" id="header">
        <a class="x-header-arrow" @click="api.closeWin()"></a>
        <div class="x-header-t">工作台-打烊安全检查</div>
      </div>
      <template>
        <el-table :data="tabledata">
          <el-table-column label="序号" width="50" type="index" fixed></el-table-column>
          <el-table-column label="检查项目" width="" fixed>
            <template slot-scope="scope">
              {{scope.row.title}}
            </template>
          </el-table-column>
          <el-table-column label="检查结果" width="120">
            <template slot-scope="scope">
              <el-button type="primary" v-if="scope.row.is_ok=='0'" @click="workok(scope.row.id,scope.row.title)" size="mini">点击确认</el-button>
              <div v-if="scope.row.is_ok=='1'" size="mini" class="x-text-g">已完成</div>
              <div v-if="scope.row.is_ok=='2'" size="mini" class="x-text-r">未完成</div>
            </template>
          </el-table-column>
          <el-table-column label="记录要点" width="">
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click="editfavo(scope.row.id,scope.row.content,scope.row.img)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <!--  -->
      <el-dialog title="" :visible.sync="edittoast" width="90%" center="true" close-on-click-modal="false" show-close="false">
        <div class="x-pro-row">
          <div class="x-pro-label">添加文字：</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入" v-model="textvalue" type="textarea" :rows="3"></el-input>
          </div>
        </div>
        <div class="x-pro-row">
          <div class="x-pro-label">添加图片：</div>
          <div class="x-pro-input">
            <el-button type="success" @click="imgPer">添加图片</el-button>
          </div>
        </div>
        <div class="x-pro-himg" :style="{'background-image':'url(' +input4+ ')','background-size':'cover','width':'6rem','height':'6rem','border-radius':'0.4rem','margin-top':'1rem'}" v-if="input4!=''" @click="imagebig = true"></div>
        <span slot="footer" class="dialog-footer">
          <div class="x-pro-gobtn" @click="okgettime" v-show="!isfromindex">提交</div>
        </span>
      </el-dialog>
      <img :src="input4" alt="" width="100%" v-if="imagebig" class="x-img-big" @click="imagebig = false">
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
	<script>
apiready = function () {
    $api.fixStatusBar($api.byId('header'));


    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          tabledata:[],
          edittoast:false,
          textvalue:'',
          input4:'',
          editid:'',
          isfromindex:false,
          cardsmonth:'',
          imagebig:false

        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;
        that.getdata()

      },
      methods: {
        getdata:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/duty/getClosed',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:that.cardsmonth
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.tabledata = ret.data.list;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //检查结果
        workok:function(id,name){
          var that = this;
          api.actionSheet({
              title: '请确认“'+ name + '”的检查结果',
              cancelTitle: '取消',
              buttons: ['已完成', '未完成']
          }, function(ret, err) {
              var index = ret.buttonIndex;
              if(index=='1'){
                that.settake(id,index)
              }else if(index=='2'){
                that.settake(id,index)
              }

          });
        },
        //检查结果 提交
        settake:function(id,index){
          let that=this;
          api.ajax({
            url:baseurl+'api/duty/setClosedState',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                cid:id,
                type:index,
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.getdata()


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //记录要点
        editfavo:function(id,con,img){
          var that = this;
          that.textvalue = con;
          that.input4 = img;
          that.editid = id;
          that.edittoast = true;

        },
        // 判断相机权限
        imgPer:function(){
          let that =this;
          var resultList = api.hasPermission({
              list:['camera','storage','photos']
          });
          if(!resultList[0].granted || !resultList[1].granted || !resultList[2].granted){
            // 没有权限
            that.reqPer()
          }else{
            // 有权限
            that.openpic()
          }
        },
        // 再请求
        reqPer:function(){
          let that =this;
          // 没有权限
          api.requestPermission({
              list:['camera','storage','photos'],
              code:1
          }, function(ret, err){
              if(ret.list[0].granted && ret.list[1].granted && ret.list[2].granted){
                // 允许
                that.openpic()
              }else{
                // 禁止
                that.noPer()
              }
              // 不再提醒
              if(ret.never){

              }
          });
        },
        // 禁止
        noPer:function(){
          let that =this;
          api.confirm({
            title: '提醒',
            msg: '没有获得 ' + '相机' + " 权限\n是否前往设置？",
            buttons: ['去设置', '取消']
          }, function(ret, err) {
            if(1 == ret.buttonIndex){
              that.reqPer();
            }
          });
        },
        //调起相机
        openpic:function(){
          let that =this;
          api.actionSheet({
              cancelTitle: '取消',
              buttons: ['相机', '相册']
          }, function(ret, err) {
              var tindex = ret.buttonIndex;
              if(tindex==1){//相机
                that.choicepic('camera')
              }else if(tindex==2){//相机
                that.choicepic('album')
              }
          });
        },
        //图片he视频上传
        choicepic:function(type){
          let that =this;
          api.getPicture({
            sourceType: type,
            encodingType: 'jpg',
            mediaValue: 'pic',
            destinationType: 'url',
            allowEdit: true,
            preview:true,
            quality: 50,
            saveToPhotoAlbum: true,
            groupName:'餐众邦'
          }, function(ret, err) {
            api.showProgress();
            if (ret) {
                console.log(JSON.stringify(ret));
                api.ajax({
                    url: baseurl+'upload/oss',
                    method: 'post',
                    data: {
                      values: {
                        "sec":$api.getStorage('apptoken'),
                      },
                      files: {
                        "file": ret.data
                      }
                    }
                }, function(ret, err) {
                  // console.log(JSON.stringify(ret));
                  // console.log(JSON.stringify(err));
                  api.hideProgress();
                  if(ret.status==1){
                    api.hideProgress();
                    // that.uploadvideo(ret.data[0].url)
                    that.input4 = ret.data[0].url;
                    // console.log(that.input4);


                  }else{
                    api.hideProgress();
                    api.toast({
                        msg: '上传失败，请重新选择',
                        duration: 3000,
                        location: 'bottom'
                    });
                  }
                });
            } else {
                api.hideProgress();
                console.log(JSON.stringify(err));
                api.toast({
                    msg: '上传失败，请重新选择',
                    duration: 3000,
                    location: 'bottom'
                });
            }
          });
        },
        //提交图片
        okgettime:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/duty/setClosed',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                cid:that.editid,
                content:that.textvalue,
                img:that.input4
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                api.alert({
                    title: '要点记录成功',
                    msg: '',
                }, function(ret, err) {
                  that.edittoast = false;
                  that.getdata()
                });


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
      }
    })
	}


	</script>
</body>
</html>
